﻿using phhui;
using System;
using System.Collections;
using System.IO;
using System.Windows.Forms;

namespace PQBlog{
    public partial class Install : Form
    {
        private XmlHelper xml;
        public Install(){
            InitializeComponent();
        }
        private void Inistall_Load(object sender, EventArgs e)
        {
            xml = new XmlHelper();
        }
        private void btn_install_Click(object sender, EventArgs e){
            if (!CharCheck.unNull(tb_name.Text)) log("名称不能为空！");
            else if (!CharCheck.unNull(tb_usn.Text)) log("管理员账号不能为空！");
            else if (!CharCheck.unNull(tb_pwd.Text)) log("密码不能为空！");
            else if (!CharCheck.strEqual(tb_pwd.Text, tb_pwd2.Text)) log("密码验证不一致！");
            else
            {
                if (!Directory.Exists("db")) Directory.CreateDirectory("db");
                xml.CreateXmlDocument("db/info.xml", "data");
                Hashtable ht = new Hashtable();
                ht.Add("dir", "dir");
                ht.Add("pwd", MD6.Encryption(tb_pwd.Text));
                ht.Add("account", tb_usn.Text);
                ht.Add("title", tb_name.Text);
                xml.InsertNode("db/info.xml","data",false,"data",null,ht);
                File.WriteAllText("db/install", "true");
                Directory.CreateDirectory("db/article");
                xml.CreateXmlDocument("db/article/dir.xml", "data");
                this.Hide();
                WinMgr.self.showLogin();
            }
        }
        private void log(string str)
        {
            lb_tip.Text = str;
            //MessageBox.Show(str);
        }

        private void refechTip(object sender, EventArgs e)
        {
            lb_tip.Text = "";
        }

        private void Install_FormClosed(object sender, FormClosedEventArgs e)
        {
            WinMgr.self.quit();
        }
    }
}
